package org.linuxsogood.boot.mysql;


import com.mysql.jdbc.Driver;

import java.sql.*;

/**
 * @author honway.liu
 * @date 2016/12/8 下午11:07
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 */
public class JdbcDemo {


    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        MyConnectionPool myConnectionPool = new MyConnectionPool();
        Connection connection = myConnectionPool.getConnection();
        String sql = "select * from msg";
        PreparedStatement prepareStatement = connection.prepareStatement(sql);
        ResultSet resultSet = prepareStatement.executeQuery();
        while (resultSet.next()) {
            String address = resultSet.getString("address");
            System.out.println(address);
        }
    }

    private static void method1() throws SQLException {
        String url = "jdbc:mysql://127.0.0.1:3306/mydb";
        String username = "root";
        String password = "redhat";
        //Class.forName("com.mysql.jdbc.Driver");
        DriverManager.registerDriver(new Driver());
        Connection connection = DriverManager.getConnection(url, username, password);
        String sql = "SELECT * FROM msg";
        PreparedStatement prepareStatement = connection.prepareStatement(sql);
        ResultSet resultSet = prepareStatement.executeQuery();
        while (resultSet.next()) {
            String address = resultSet.getString("address");
            System.out.println(address);
        }
    }

}
